package com.zw.yzk.kabu.data.repository;

import com.zw.yzk.kabu.data.network.task.Task;
import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.entity.GoodsDetailsEntity;
import com.zw.yzk.kabu.data.network.service.GoodsDetailsService;
import com.zw.yzk.kabu.data.network.task.GoodsDetailsTask;

import javax.inject.Inject;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by zhanwei on 2016/12/24.
 */

public class GoodsDetailsRepository extends CommonRepository {

    @Inject
    public GoodsDetailsRepository() {
    }

    @Override
    protected Observable connectServer(Task task) {
        GoodsDetailsService service = ServiceGenerator.createService(GoodsDetailsService.class);
        GoodsDetailsTask goodsDetailsTask = (GoodsDetailsTask) task;
        return service.getGoodsDetails(goodsDetailsTask.goodsId, task.userId, task.accessToken);
    }

    @Override
    protected Func1<GoodsDetailsEntity, Observable> getServerData() {
        return new Func1<GoodsDetailsEntity, Observable>() {
            @Override
            public Observable call(GoodsDetailsEntity entity) {
                return Observable.just(entity);
            }
        };
    }

}
